В Python блок else может располагаться не только после if, но и после for и while. Код внутри else выполняется, если цикл не был прерван оператором break.
Обычный способ использования этого — найти что-то в цикле и выйти из него через break, когда нужный элемент найден:
>>> first_odd = None >>> for x in [2, 3, 4, 5]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... >>> first_odd 3
>>> for x in [2, 4, 6]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... ... ValueError: В списке нет нечетных элементов
В Python блок else может располагаться не только после if, но и после for и while. Код внутри else выполняется, если цикл не был прерван оператором break.
Обычный способ использования этого — найти что-то в цикле и выйти из него через break, когда нужный элемент найден:
>>> first_odd = None >>> for x in [2, 3, 4, 5]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... >>> first_odd 3
>>> for x in [2, 4, 6]: ... if x % 2 == 1: ... first_odd = x ... break ... else: ... raise ValueError('В списке нет нечетных элементов') ... ... ValueError: В списке нет нечетных элементов
However, analysts are positive on the stock now. “We have seen a huge downside movement in the stock due to the central electricity regulatory commission’s (CERC) order that seems to be negative from 2014-15 onwards but we cannot take a linear negative view on the stock and further downside movement on the stock is unlikely. Currently stock is underpriced. Investors can bet on it for a longer horizon," said Vivek Gupta, director research at CapitalVia Global Research.
Dump Scam in Leaked Telegram Chat
A leaked Telegram discussion by 50 so-called crypto influencers has exposed the extraordinary steps they take in order to profit on the back off unsuspecting defi investors. According to a leaked screenshot of the chat, an elaborate plan to defraud defi investors using the worthless “$Few” tokens had been hatched. $Few tokens would be airdropped to some of the influencers who in turn promoted these to unsuspecting followers on Twitter.